package com.andnnl.bigdecimal;

import javafx.beans.binding.DoubleExpression;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * Created by chenss on 2021/7/14.
 */
public class TestBigDecimal {
    public static void main(String[] args) {
        BigDecimal a= new BigDecimal(0.075);

        BigDecimal a1= new BigDecimal(10.075);

        BigDecimal a2= new BigDecimal(100.075);

        BigDecimal b= new BigDecimal(0.074);

        BigDecimal b1= new BigDecimal(10.074);

        BigDecimal b2= new BigDecimal(100.074);

        BigDecimal c= new BigDecimal("0.075");

        BigDecimal c1= new BigDecimal("10.075");

        BigDecimal c2= new BigDecimal("100.075");

        DecimalFormat df= new DecimalFormat("#0.00");

        BigDecimal one=BigDecimal.ONE;//0.07

        System.out.println(a.divide(one, 2, RoundingMode.HALF_UP).doubleValue());//0.08

        System.out.println(a.divide(one).add(new BigDecimal("0.0000000001")).setScale(2, RoundingMode.HALF_UP).doubleValue());//0.07

        System.out.println(b.divide(one, 2, RoundingMode.HALF_UP).doubleValue());//0.07

        System.out.println(b.divide(one).add(new BigDecimal("0.0000000001")).setScale(2, RoundingMode.HALF_UP).doubleValue());//0.07

        System.out.println(df.format(0.074));//0.07

        System.out.println(df.format(0.075));//0.08

        System.out.println(c.divide(one, 2, RoundingMode.HALF_UP).doubleValue());

        System.out.println("----------------------------");//10.07

        System.out.println(a1.divide(one, 2, RoundingMode.HALF_UP).doubleValue());//10.08

        System.out.println(a1.divide(one).add(new BigDecimal("0.0000000001")).setScale(2, RoundingMode.HALF_UP).doubleValue());//10.7

        System.out.println(b1.divide(one, 2, RoundingMode.HALF_UP).doubleValue());//10.07

        System.out.println(b1.divide(one).add(new BigDecimal("0.0000000001")).setScale(2, RoundingMode.HALF_UP).doubleValue());//10.07

        System.out.println(df.format(10.074));//10.07

        System.out.println(df.format(10.075));//10.08

        System.out.println(c1.divide(one, 2, RoundingMode.HALF_UP).doubleValue());

        System.out.println("----------------------------");//100.08

        System.out.println(a2.divide(one, 2, RoundingMode.HALF_UP).doubleValue());//100.08

        System.out.println(a2.divide(one).add(new BigDecimal("0.0000000001")).setScale(2, RoundingMode.HALF_UP).doubleValue());//100.07

        System.out.println(b2.divide(one, 2, RoundingMode.HALF_UP).doubleValue());//100.07

        System.out.println(b2.divide(one).add(new BigDecimal("0.0000000001")).setScale(2, RoundingMode.HALF_UP).doubleValue());//100.07

        System.out.println(df.format(100.074));//100.08

        System.out.println(df.format(100.075));//100.08

        System.out.println(c2.divide(one, 2, RoundingMode.HALF_UP).doubleValue());

        System.out.println("----------------------------");//
        BigDecimal int10=new BigDecimal("10.00");
        BigDecimal intlPrice=new BigDecimal("2.01");;
        int rs = intlPrice.multiply(int10).setScale(0, RoundingMode.UP).intValue();
        System.out.println(rs);

    }
}
